package com.yzt.zhuju.utils;

import android.app.Application;
import android.util.Log;

import com.yzt.zhuju.config.AppConfigCacheManager;
import com.yzt.zhuju.manager.FontManager;
import com.yzt.zhuju.network.entity.sysConfig.SystemConfigBean;
import com.yzt.zhuju.network.entity.sysConfig.SystemConfigHideBean;
import com.yzt.p_base.utils.SharedPreferenceUtil;
import com.yzt.p_base.utils.ThreadCenter;

import org.litepal.LitePal;

import java.util.List;

/**
 * author : bob
 * date   : 2022/11/29
 * desc   :
 */
public class SDKInitManager {

    private static final String TAG = "SDKInitManager";

    public static SDKInitCallBack callBack;

    /**
     * init App system content
     * view config ,system config ,obs domain config
     */
    public static void initAppConfigCacheManager(AppConfigCacheManager.DataCallBackEvent<SystemConfigBean> systemConfigEvent,
                                                 AppConfigCacheManager.DataCallBackEvent<List<SystemConfigHideBean>> viewConfig) {
        AppConfigCacheManager.getInstance().init(systemConfigEvent, viewConfig);
    }

    /**
     * init App system content
     * view config ,system config ,obs domain config
     */
    public static void initAppConfigCacheManager() {
        initAppConfigCacheManager(null, null);
    }

    /**
     * 是否 安装首次启动
     */
    public static boolean isFirstInstalled() {
        return SharedPreferenceUtil.getInstance().getValue("isFirstInstalled", true);
    }

    /**
     * 初始化所有SDK
     */
    public static void initAll(Application application) {

        if (SystemUtil.inMainProcess(application)) {

            ThreadCenter.postNormalThread(() -> {

                Log.i(TAG, "SDKInitManager---initAll");

                // 本地存储
                initOtherSDk(application);

                // 字体管理器
                FontManager.getInstance().init(application);
            });
        }
        if (callBack != null) {
            callBack.RYunInit(application);
        }
    }

    /**
     * 初始化 LitePal
     */
    public static void initOtherSDk(Application application) {
        ThreadCenter.postNormalThread(new Runnable() {
            @Override
            public void run() {
                LitePal.initialize(application);
                //删除7天前的缓存
                PersonalDetailCacheManager.deleteAWeekBefore();
            }
        });
    }

    public interface SDKInitCallBack {

        void RYunInit(Application application);
    }
}
